package fmu.pi.view.draw;

import java.sql.SQLException;

import javafx.scene.chart.CategoryAxis;
import javafx.scene.chart.LineChart;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
import fmu.pi.business.MovimentacaoBusiness;
import fmu.pi.business.vo.MovimentacaoVO;
import fmu.pi.utils.Utils;

public class ChartsDrawer {
	
	private MovimentacaoBusiness movimentacaoBO;
	
	private String lineChartCss = "/fmu/pi/view/fxml/css/lineChart.css";
	
	
	public ChartsDrawer(MovimentacaoBusiness bo) {
		super();
		movimentacaoBO = bo;
		
	}

	
	public LineChart<String, Number> creatHomeChart() throws SQLException {
		 
        final CategoryAxis xAxis = new CategoryAxis();
        final NumberAxis yAxis = new NumberAxis();
        final LineChart<String,Number> lc = new LineChart<String,Number>(xAxis,yAxis);
        
        lc.setTitle("Balanço Anual");
        lc.setPrefWidth(650);
        lc.setPrefHeight(400);
        lc.setAnimated(true);
        
        lc.getStylesheets().add(lineChartCss);
      
        xAxis.setLabel("Mês");
        yAxis.setLabel("Valor");
        
        XYChart.Series<String,Number> series = new XYChart.Series<String,Number>();
        series.setName("" + Utils.anoAtual());
       
        for (MovimentacaoVO mov : movimentacaoBO.obterBalancoAnual(Utils.anoAtual())) {
        	 series.getData().add(new XYChart.Data<String,Number>(mov.getMes(), mov.getValor()));
		}
  
        lc.getData().add(series);
        return lc;
    }

}
